package com.xframe.xdal.core.model.sqlbuilder;



import com.xframe.xdal.core.constant.DataSourceTypeEnums;

import java.util.HashMap;
import java.util.Map;

public class DbExpression {

    private static DbExpression dbExpression = new DbExpression();


    public static DbExpression getDbExpression() {
        return dbExpression;
    }

    /**
     * 数据库表达式集合
     */
    private Map<String, String> dbExpList = new HashMap<>();

    /**
     * 根据数据库类型 获取数据库表达式
     *
     * @param exp                 表达式
     * @param dataSourceTypeEnums 数据库类型
     * @return
     */
    public String getExpression(String exp, DataSourceTypeEnums dataSourceTypeEnums) {
        String dbExp = dbExpList.get(exp.toUpperCase() + "_" + dataSourceTypeEnums.toString());
        if (dbExp == null) {
            return exp;
        }
        return dbExp;
    }

    public DbExpression() {
        dbExpList.put("SYSDATE_" + DataSourceTypeEnums.MySql.toString(), "now()");
        dbExpList.put("SYSDATE_" + DataSourceTypeEnums.ClickHouse.toString(), "now()");
        dbExpList.put("SYSDATE_" + DataSourceTypeEnums.Oracle.toString(), "sysdate");
        dbExpList.put("SYSDATE_" + DataSourceTypeEnums.SqlServer.toString(), "getdate()");
    }
}
